import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/CurrentIndexProvider.dart';
import 'home/Home.dart';
import 'my/My.dart';
import 'study/Study.dart';

class Index extends StatefulWidget {
  Index({Key key}) : super(key: key);

  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<Index> {
  // 配置底部导航
  final List<BottomNavigationBarItem> navigationItems = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      label: '首页',
    ),
     BottomNavigationBarItem(
      icon: Icon(Icons.star_rounded),
      label: '学习',
    ),
     BottomNavigationBarItem(
      icon: Icon(Icons.person),
      label: '我的',
    ),
  ];

  // 头部信息
  final header = [
    AppBar(
      title: Text('首页'),
      centerTitle: true,
      elevation: 0,
    ),
    AppBar(
      title: Text('学习列表'),
      centerTitle: true,
      elevation: 0,
    ),
    AppBar(
      title: Text('个人中心'),
      centerTitle: true,
      elevation: 0,
    ),
  ];

  // 页面信息
  final page = [
    Home(),
    Study(),
    My(),
  ];

  @override
  Widget build(BuildContext context) {
    int currentIndex = context.watch<CurrentIndexProvider>().currentIndex;
    return Scaffold(
      appBar: header[currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        items: navigationItems,
        currentIndex: currentIndex,
        onTap: context.read<CurrentIndexProvider>().changeIndex,
      ),
      body: page[currentIndex],
    );
  }
}